package com.cqc.textlinkify01;

import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView tv2;
    private TextView tv3;
    private TextView tv4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        tv2 = (TextView) findViewById(R.id.tv2);
        Spanned spanned = Html.fromHtml(getResources().getString(R.string.text2));
        tv2.setText(spanned);
        tv2.setMovementMethod(LinkMovementMethod.getInstance());


        tv3 = (TextView) findViewById(R.id.tv3);
        tv3.setText(Html.fromHtml("百度：<a href=\"http://www.baidu.com/\">百度</a>,手机号：<a href=\"tel:123456789\">123456789</a>"));
        tv3.setMovementMethod(LinkMovementMethod.getInstance());


        tv4 = (TextView) findViewById(R.id.tv4);
        SpannableString text4 = new SpannableString("打开百度，拨打手机号");
        text4.setSpan(new StyleSpan(Typeface.BOLD),2,4,SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
        text4.setSpan(new URLSpan("http://www.baidu.com/"),2,4,SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
        text4.setSpan(new URLSpan("tel:123456789"),7,10,SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv4.setText(text4);
        tv4.setMovementMethod(LinkMovementMethod.getInstance());

    }
}
